package com.wwu.develop.controller;

import com.wwu.common.utils.SpringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 开发助手前端控制器
 * @author 一蓑烟雨
 * @version 1.0.0
 * @date 2023-08-04 18:14
 */
@Controller
@RequestMapping("/develop")
public class AssistantController {
    /**
     * 请求转发developCode代码生成主页面
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/8/4 18:25
     */
    @GetMapping("/assistant/developCodeMain")
    public String developCodeMainHtml() {
        return "develop/assistant/develop-code-main";
    }

    /**
     * 请求转发developApi开发Api页面
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/8/4 18:25
     */
    @GetMapping("/assistant/developApiMain")
    public String developApiMainHtml(HttpServletRequest request) {
        ApplicationContext applicationContext = SpringUtils.getApplicationContext();
        Environment env = applicationContext.getEnvironment();
        String apiPath = null;
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String path = env.getProperty("server.servlet.context-path");
            apiPath = "http://" + ip + ":" + port + path + "/doc.html";
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "redirect:"+apiPath;
    }

    /**
     * 请求转发developLog开发日志页面
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/8/4 18:26
     */
    @GetMapping("/assistant/developLogMain")
    public String developLogMainHtml() {
        return "develop/assistant/develop-log-main";
    }
}
